﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="khoa_dao_tao.aspx.cs" MasterPageFile="~/master_form.master" Inherits="App_Form_DanhMuc_khoa_dao_tao" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script type="text/javascript">
        Ext.require([
           'Ext.selection.CellModel',
           'Ext.grid.*',
           'Ext.data.*',
           'Ext.util.*',
           'Ext.state.*',
           'Ext.form.*',
           'Ext.grid.Panel'
        ]);

        Ext.onReady(function () {

            Ext.QuickTips.init();

            var bd = Ext.getBody();

            var gridForm = Ext.create('Ext.form.Panel',
            {
                id: 'company-form',
                frame: true,
                bodyPadding: 5,
                layout:
                {
                    type: 'table',
                    columns: 2
                },
                fieldDefaults:
                {
                    labelAlign: 'left',
                    msgTarget: 'side'
                },

                items:
                [
                    {
                        columnWidth: '40%',
                        margin: '0 0 0 10',
                        xtype: 'fieldset',
                        title: 'Thông tin chính',
                        defaults:
                        {
                            width: 300,
                            labelWidth: 90
                        },
                        defaultType: 'textfield',
                        items:
                        [
                            {
                                xtype: 'hidden', fieldLabel: 'tr', id: 'ID', name: 'ID'
                            },
                            {
                                xtype: 'combo',
                                value: '',
                                emptyText: 'Hệ đào tạo',
                                triggerAction: 'all',
                                forceSelection: true,
                                editable: false,
                                fieldLabel: 'Hệ đào tạo',
                                id: 'id_ht_dt',
                                name: 'id_ht_dt',
                                displayField: 'Ten',
                                valueField: 'ID',
                                queryMode: 'local',
                                store: null,
                                listeners: {
                                    select: function (combo, record, index) {
                                        if (record.length > 0) {
                                            var id_ht_dt = record[0].get('ID');
                                            //Goi service
                                            wtkb.Fjson_Khoa_Lke(id_ht_dt, khoa_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                        }
                                    }
                                }
                            },
                            {
                                fieldLabel: 'Tên', id: 'Ten', name: 'Ten'
                            },
                            {
                                fieldLabel: 'Ghi chú', id: 'GhiChu', name: 'GhiChu'
                            },

                            {
                                xtype: 'fieldcontainer',
                                combineErrors: true,
                                layout:
                                    {
                                        type: 'hbox',
                                        defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                                    },
                                items:
                                [
                                    {
                                        name: 'add',
                                        xtype: 'button',
                                        width: 90,
                                        icon: '../../shared/icons/fam/add.gif',
                                        text: 'Thêm mới',
                                        handler: function () {
                                            var b_ma = Ext.getCmp('ID').getValue(),
                                                b_ten = Ext.getCmp('Ten').getValue(),
                                                b_he = Ext.getCmp('id_ht_dt').getValue();
                                               b_gchu = Ext.getCmp('GhiChu').getValue();
                                            
                                               if (b_ten == "") { return alert("Chưa nhập tên"); }
                                               if (b_he == "") { return alert("Chưa chọn hệ đào tạo"); }
                                               wtkb.Fjson_Khoa_NH(b_ma, b_ten, b_gchu,b_he, khoa_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                        }
                                    },
                                    {
                                        name: 'moi',
                                        xtype: 'button',
                                        width: 90,
                                        icon: '../../shared/icons/fam/refesh.png',
                                        text: 'Mới',
                                        handler: function () {
                                            this.up('form').getForm().reset();
                                        }
                                    },
                                    {
                                        name: 'xoa',
                                        xtype: 'button',
                                        width: 90,
                                        text: 'Xóa',
                                        handler: function () {
                                            var c = confirm("Bạn có chắc chắn xóa không ?"); if (!c) return;
                                            var b_rd = Ext.getCmp("khoa").getSelectionModel().getSelection();
                                            if (!b_rd[0]) { return alert("Chưa chọn khóa đào tạo để xóa") };
                                            var b_ma = b_rd[0].get("ID");
                                            b_ht_dt = Ext.getCmp('id_ht_dt').getValue();
                                            wtkb.Fjson_Khoa_Xoa(b_ma, b_ht_dt, khoa_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                        }
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        columnWidth: '60%',
                        xtype: 'gridpanel',
                        margin: '0 0 0 1',
                        store: null,
                        id: 'khoa',
                        width: 400,
                        height: 400,
                        title: 'Danh sách khóa đào tạo',
                        columns: [
                            { id: 'MA1', flex: 1, text: 'ID', width: 90, sortable: true, hidden: true, dataIndex: 'ID' },
                            { id: 'TEN1', text: 'Tên', width: 150, flex: 1, sortable: true, dataIndex: 'Ten' },
                            { id: 'TEN2', text: 'Ghi chú', width: 250, flex: 1, sortable: true, dataIndex: 'GhiChu' }
                        ],
                        listeners: {
                            selectionchange: function (model, records) {
                                if (records[0]) {
                                    this.up('form').getForm().loadRecord(records[0]);

                                }
                            }
                        }
                    }
                ],
                renderTo: bd
            });
            wtkb.Fjson_HeDaoTao_Lke(P_LOAD_TTCHUNG, P_LOI_CSDL, P_LOI_TGIAN);
        });

    </script>
    </asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script type="text/javascript">
        function P_LOAD_TTCHUNG(b_kq) {
            //debugger;
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                //var a_kq = b_kq.split('@');
                //var b_chuoi1 = CH_JSON(a_kq[0]),
                //   b_chuoi2 = CH_JSON(a_kq[1])
                var b_chuoi2 = CH_JSON(b_kq);
                //var a_data1 = Ext.create('Ext.data.Store', {
                //    fields: ['ID', 'Ten', 'GhiChu'],
                //    data: b_chuoi1
                //});
                //var c = Ext.getCmp('khoa');
                //c.bindStore(a_data1);


                var a_data2 = Ext.create('Ext.data.Store', {
                    fields: ['ID', 'Ten'],
                    data: b_chuoi2
                });

                var ds = Ext.getCmp('id_ht_dt');
                ds.bindStore(a_data2);
            }

        }
        function khoa_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                
                var b_chuoi1 = CH_JSON(b_kq);
                var a_data1 = Ext.create('Ext.data.Store', {
                    fields: ['ID', 'Ten', 'GhiChu'],
                    data: b_chuoi1
                });
                var c = Ext.getCmp('khoa');
                c.bindStore(a_data1);
            }

        }
    </script>
    </asp:Content>